Skip to content

Add a Go example exercising hostedtool.MCPServer with the OpenAI Responses provider - #665

Open
PratikDhanave (PratikDhanave) wants to merge 5 commits into
microsoft:mainfrom
PratikDhanaveFork:openai-hosted-mcp-example
Open

Add a Go example exercising hostedtool.MCPServer with the OpenAI Responses provider#665
PratikDhanave (PratikDhanave) wants to merge 5 commits into
microsoft:mainfrom
PratikDhanaveFork:openai-hosted-mcp-example

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

What

Adds a new example examples/02-agents/providers/openai/hosted_mcp/main.go that wires a hosted MCP server into an OpenAI Responses agent.

The example:

  • builds an OpenAI Responses agent via openaiprovider.NewResponsesAgent,
  • attaches []tool.Tool{&hostedtool.MCPServer{...}} pointing at the public Microsoft Learn MCP endpoint (https://learn.microsoft.com/api/mcp) with AllowedTools set,
  • runs the agent and iterates the response contents, printing any *message.MCPServerToolCallContent and hosted-MCP *message.ToolApprovalRequestContent,
  • guards the live run behind an OPENAI_API_KEY check, printing a skip message when it is absent (consistent with the other provider examples).

It is registered in the cmd/verifyexamples harness alongside the existing hosted-tool examples (foundry step14_code_interpreter, step21_web_search, step23_local_mcp).

Why

provider/openaiprovider/responses.go already maps *hostedtool.MCPServer onto responses.ToolMcpParam (server label, server URL/connector id, description, allowed tools, headers, authorization), but no example exercised it — hostedtool.MCPServer did not appear anywhere under examples/. The existing examples only wired hostedtool for CodeInterpreter and WebSearch. This mirrors the .NET and Python SDKs, which each ship a hosted-MCP agent sample, and fills the missing OpenAI Responses variant for cross-SDK parity. The example follows the same structure as the existing hosted-tool step examples.

Testing

  • go build ./...
  • go vet ./examples/... ./cmd/verifyexamples/...
  • go test ./cmd/verifyexamples/...

all pass. The example is a docs/example addition; its live body is env-gated so it compiles and vets without credentials.

Copilot AI review requested due to automatic review settings July 23, 2026 08:21
@PratikDhanave
PratikDhanave (PratikDhanave) requested a review from a team as a code owner July 23, 2026 08:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new OpenAI Responses provider example demonstrating how to wire a hosted MCP server (hostedtool.MCPServer) into an agent, and registers that example with the cmd/verifyexamples harness.

Changes:

  • Added examples/02-agents/providers/openai/hosted_mcp/main.go to run an OpenAI Responses agent with the Microsoft Learn hosted MCP endpoint and print MCP tool-call / approval-request contents.
  • Registered the new example in cmd/verifyexamples/examples.go so it can be verified (env-gated on OPENAI_API_KEY).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
examples/02-agents/providers/openai/hosted_mcp/main.go New example showing a hosted MCP server tool used through an OpenAI Responses agent and printing MCP-related response contents.
cmd/verifyexamples/examples.go Adds the new hosted MCP example to the verifyexamples registry with OPENAI_API_KEY gating.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread examples/02-agents/providers/openai/hosted_mcp/main.go
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added the parity-approved Go API consistency review found no parity issues label Jul 23, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Add examples/02-agents/providers/openai/hosted_mcp demonstrating the
hostedtool.MCPServer tool with an OpenAI Responses agent. It attaches a
remote hosted MCP server (Microsoft Learn), runs the agent, and inspects
the response for MCPServerToolCallContent and MCP approval requests. The
live run is guarded behind an OPENAI_API_KEY check. Register the example
in the verifyexamples harness alongside the other hosted-tool examples.
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

# Conflicts:
#	cmd/verifyexamples/examples.go
@github-actions github-actions Bot added area:examples Changes files in the examples area area:tooling Changes files in the tooling area size:medium At most 100 changed lines across at most 5 files pending-auto-risk Automatic risk classification is in progress labels Aug 20, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added failed-auto-risk Automatic risk classification was inconclusive or failed and removed pending-auto-risk Automatic risk classification is in progress labels Aug 20, 2026
@github-actions github-actions Bot added pending-auto-risk Automatic risk classification is in progress risk:low Limited blast radius and straightforward rollback and removed failed-auto-risk Automatic risk classification was inconclusive or failed labels Aug 22, 2026
@github-actions github-actions Bot removed the pending-auto-risk Automatic risk classification is in progress label Aug 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Parity Review — PR #665

Scope

This PR adds one new example file (examples/02-agents/providers/openai/hosted_mcp/main.go) and registers it in the cmd/verifyexamples harness. No exported Go types, functions, or methods are added or changed.

Cross-SDK Sample Alignment

The hosted-MCP scenario is covered in both upstream SDKs:

  • Python: python/samples/02-agents/providers/openai/client_with_hosted_mcp.py — demonstrates never_require, always_require, and selective-approval modes with and without sessions
  • .NET: dotnet/samples/02-agents/ModelContextProtocol/ResponseAgent_Hosted_MCP/Program.cs — demonstrates NeverRequire and AlwaysRequire modes with ToolApprovalRequestContent handling

The Go example fills the previously missing OpenAI Responses variant for this scenario. It targets the no-explicit-approval-mode variant (analogous to never_require in Python), uses microsoft_docs_search via AllowedTools, and correctly inspects *message.MCPServerToolCallContent and *message.ToolApprovalRequestContent from the response — matching the intent of both upstream samples.

Pre-existing Structural Note (not introduced by this PR)

The Go hostedtool.MCPServer struct currently has no ApprovalMode field. Both Python (approval_mode kwarg) and .NET (HostedMcpServerToolApprovalMode enum) expose explicit approval-mode control, so the Go SDK cannot yet demonstrate the interactive approval workflow shown in the upstream samples. This gap predates this PR and is out of scope here, but maintainers may want to track it as a follow-up.

Verdict

✅ No parity issues introduced by this PR. The example aligns in concept, endpoint, and response-inspection pattern with the upstream Python and .NET samples. No exported Go API surface changed.

Generated by Go API Consistency Review Agent · sonnet46 · 32.5 AIC · ⌖ 5.79 AIC · ⊞ 6K ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:examples Changes files in the examples area area:tooling Changes files in the tooling area parity-approved Go API consistency review found no parity issues risk:low Limited blast radius and straightforward rollback size:medium At most 100 changed lines across at most 5 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants